Raghav K. Chhetri

07-21-2021

There are multiple ways to compute FFT in Python:

  1. numpy.fft
  2. scipy.fftpack -- Considered legacy. SciPy recommends using scipy.fft
  3. scipy.fft
  4. pyfftw
  5. cupy.fft -- NVIDIA's library that evaluates FFTs on GPUs
  6. torch.FFT

1D FFT (for time-series data)

General comments:

fft takes longer if npnts is not a multiple of 2 and even longer if it is a prime

The frequency axis has been defined in different ways in fft_powerspectrum_plot below:

Let's generate a 1D signal and add some noise to it:

Let's plot to see what the signal looks like and what its power spectrum looks like (no denoising yet):

Now, let's denoise frequencies with power spectrum below 1:

If we plot the frequency axis to show mirrored values in the negative axis too, this is what it looks like:

Or, using method 3, which uses rfft instead of fft:


Spurious frequency peaks in Amplitude Spectrum

Let's change the frequencies of the signal to non-integer values. When we do so, we see that the FFT amplitude shows up with spurious frequency peaks

One way to mitigate these additional frequency components is to use a longer signal, as shown below:

Another option is to denoise lower frequencies like we did earlier


2D FFT (working with images)

1. Blurring an image with 2D FFT

Adapted from the following numpy example


2. Gaussian blur implemented using FFT convolution: fftconvolve

Notice the dark borders around the image, due to zero-padding beyond its boundaries. scipy.ndimage.gaussian_filter gets rid of this artifact.


3. Gaussian blur using SciPy.ndimage

Adapted from the following SciPy lecture

Note that a Gaussian filter smooths out the noise and the edges. Median filter averages the noise and preserves the edges better


Band-pass filtering by Difference of Gaussians

Adapted from the following SciKit-Image documentation

Band-pass filters attenuate signal frequencies outside of a range (band) of interest. In image analysis, they can be used to denoise images while at the same time reducing low-frequency artifacts such a uneven illumination. Band-pass filters can be used to find image features such as blobs and edges.

One method for applying band-pass filters to images is to subtract an image blurred with a Gaussian kernel from a less-blurred image. This example shows two applications of the Difference of Gaussians approach for band-pass filtering.

More on DoG here

1. Denoise image and reduce shadows
2. Enhance edges in an image

Diffraction-limited imaging simulation

Coherent Image Simulation:

Note that the ideal image field is blurred by the impulse response function of the imaging system, h(u,v)= FFT[H(Fx,Fy)]

i.e., Image(u,v) = Ideal_Image(u,v) convolved with h(u,v)

This is implemented in frequency-domain as follows:

Gi(Fx,Fy)= H*FFT(Ideal_Image)

So, actual image field, ui(u,v) = IFFT(Gi)

Next, let's account for surface roughness of the object by adding a random complex exponential phase term to the field:

The irradiance image that we get is thus impeded further by the prescence of speckles (more apparent with imshow Ii**0.5 so plotting that above)

Incoherent Image simulation:

Notice that the image quality in case of incoherent imaging is better than than with coherent imaging. Also, there are no ringing artifacts or speckle features in the image.